package cn.edu.dgut.css.sai.springsecuritygiteeexperiment.util;

import cn.edu.dgut.css.sai.springsecuritygiteeexperiment.GiteeOAuth2LoginConfigurer;
import cn.edu.dgut.css.sai.springsecuritygiteeexperiment.config.OAuth2Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

import javax.annotation.PostConstruct;
import java.net.URLEncoder;
import java.text.MessageFormat;

@Component
public class GiteeOauth2Util {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public OAuth2Config oAuth2Config;

    @Autowired
    private GiteeOauth2Util giteeOauth2Util;

    public static GiteeOauth2Util util = new GiteeOauth2Util();

    private String giteeOauth2WebviewURL = null;

    @PostConstruct
    private void init(){
        util = giteeOauth2Util;
        logger.debug(oAuth2Config.toString());
        giteeOauth2WebviewURL = UriComponentsBuilder
                .fromUriString(oAuth2Config.getUrlPattern())
                .encode()
                .buildAndExpand(oAuth2Config.getClientId(),oAuth2Config.getRedirectUri())
                .toString();

    }

    public String getGiteeOauth2WebviewURL(){
        return giteeOauth2WebviewURL;
    }
}
